package com.lottery.game.common.utils;

import java.util.Random;

public class CodeUtils {

    private static final String [] RAND_NUMBERS = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

    public static String rand(int length) {
        if (length <= 0) {
            length = 6;
        }
        Random random = new Random();
        String code = "";
        for (int i = 0; i < length; i++) {
            code = code + RAND_NUMBERS[random.nextInt(10)];
        }
        return code;
    }

    public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
            "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
            "W", "X", "Y", "Z" };


    public static String generateShortUuid(int length) {
        if (length <= 0) {
            length = 6;
        }
        Random random = new Random();
        String code = "";
        for (int i = 0; i < length; i++) {
            code = code + chars[random.nextInt(chars.length)];
        }
        return code;

    }
}
